package lanou3g.myfirstapp36kr.activity;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import lanou3g.myfirstapp36kr.myvolleysingleton.Colection;
import lanou3g.myfirstapp36kr.R;
import lanou3g.myfirstapp36kr.adapter.MyColectionAdapter;
import lanou3g.myfirstapp36kr.base.BaseActivity;
import lanou3g.myfirstapp36kr.myvolleysingleton.DaoMasterSingleton;

/**
 * Created by dllo on 16/8/16.
 */
public class ColectionActivity extends BaseActivity {
    private ListView listView;
    private List<Colection> data;
    private MyColectionAdapter adapter;
    @Override
    protected int getLayout() {
        return R.layout.activity_my_colection;
    }

    @Override
    protected void initView() {
        listView = (ListView) findViewById(R.id.lv_colection);
        data = new ArrayList<>();
        adapter = new MyColectionAdapter(this);
        findViewById(R.id.iv_back_colection).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    protected void initData() {
        data = DaoMasterSingleton.getDaoMasterSingleton().getColectionDao().queryBuilder().list();
        adapter.setData(data);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(ColectionActivity.this, NewsDetailsActivity.class);
                Colection bean = (Colection) adapterView.getAdapter().getItem(i);
                String pictureUrl = bean.getFeatureImg();
                //if (BuildConfig.DEBUG) Log.d("Fragmentnews______", pictureUrl);
                intent.putExtra("pictureUrl", pictureUrl);
                String name = bean.getName();
                intent.putExtra("name", name);
                //if (BuildConfig.DEBUG) Log.d("Fragmentnews===", name);
                String title = bean.getTitle();
                intent.putExtra("title", title);
                String detailsUrl = bean.getDetailsUrl();
                intent.putExtra("detailsUrl",detailsUrl);
                //String feedId = bean.getId();
                //String detailsUrl = "https://rong.36kr.com/api/mobi/news/" + feedId;
                //intent.putExtra("detailsUrl", detailsUrl);
                long publishTime = bean.getTime();
                intent.putExtra("publishTime", publishTime);
                long Id = bean.getId();
                intent.putExtra("Id",Id);
                String columnName = bean.getColumnName();
                intent.putExtra("columnName",columnName);
                startActivity(intent);

            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        data = DaoMasterSingleton.getDaoMasterSingleton().getColectionDao().queryBuilder().list();
        adapter.setData(data);

    }
}
